/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package jpa.entities;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Giovanni
 */
@Entity
@Table(name = "ack")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Ack.findAll", query = "SELECT a FROM Ack a"),
    @NamedQuery(name = "Ack.findByUserMail", query = "SELECT a FROM Ack a WHERE a.ackPK.userMail = :userMail"),
    @NamedQuery(name = "Ack.findByEventId", query = "SELECT a FROM Ack a WHERE a.ackPK.eventId = :eventId"),
    @NamedQuery(name = "Ack.findByInviteEventId", query = "SELECT a FROM Ack a WHERE a.ackPK.inviteEventId = :inviteEventId"),
    @NamedQuery(name = "Ack.findByInviteSender", query = "SELECT a FROM Ack a WHERE a.ackPK.inviteSender = :inviteSender"),
    @NamedQuery(name = "Ack.findByInviteReceiver", query = "SELECT a FROM Ack a WHERE a.ackPK.inviteReceiver = :inviteReceiver"),
    @NamedQuery(name = "Ack.findByResponse", query = "SELECT a FROM Ack a WHERE a.response = :response")})
public class Ack implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected AckPK ackPK;
    @Size(max = 7)
    @Column(name = "RESPONSE")
    private String response;
    @JoinColumns({
        @JoinColumn(name = "INVITE_EVENT_ID", referencedColumnName = "EVENT_ID", insertable = false, updatable = false),
        @JoinColumn(name = "INVITE_SENDER", referencedColumnName = "SENDER", insertable = false, updatable = false),
        @JoinColumn(name = "INVITE_RECEIVER", referencedColumnName = "RECEIVER", insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private Invite invite;
    @JoinColumn(name = "EVENT_ID", referencedColumnName = "ID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Event event;
    @JoinColumn(name = "USER_MAIL", referencedColumnName = "MAIL", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private User user;

    public Ack() {
    }

    public Ack(AckPK ackPK) {
        this.ackPK = ackPK;
    }

    public Ack(String userMail, int eventId, int inviteEventId, String inviteSender, String inviteReceiver) {
        this.ackPK = new AckPK(userMail, eventId, inviteEventId, inviteSender, inviteReceiver);
    }

    public AckPK getAckPK() {
        return ackPK;
    }

    public void setAckPK(AckPK ackPK) {
        this.ackPK = ackPK;
    }

    public String getResponse() {
        return response;
    }

    public void setResponse(String response) {
        this.response = response;
    }

    public Invite getInvite() {
        return invite;
    }

    public void setInvite(Invite invite) {
        this.invite = invite;
    }

    public Event getEvent() {
        return event;
    }

    public void setEvent(Event event) {
        this.event = event;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (ackPK != null ? ackPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Ack)) {
            return false;
        }
        Ack other = (Ack) object;
        if ((this.ackPK == null && other.ackPK != null) || (this.ackPK != null && !this.ackPK.equals(other.ackPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "jpa.entities.Ack[ ackPK=" + ackPK + " ]";
    }
    
}
